package com.tgu.home_action.dao;

import com.tgu.home_action.pojo.Admin;
import com.tgu.home_action.pojo.LiveNess;
import com.tgu.home_action.pojo.Volunteer;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.sql.Timestamp;
import java.util.List;

@Repository
public interface LiveNessMapper {
    @Insert("insert into liveness (volunteer_id,date) values(#{volunteerId},#{date})")
    void insertLiveNess(LiveNess liveNess);

    @Select("select date from liveness where id=1")
    Timestamp getById(int i);

    @Select("select * from liveness where volunteer_id=#{volunteerId} and date=#{date}")
    LiveNess getByVolunteerIdAndDate(LiveNess liveNess);

    /**
     * 查询30天内的活跃天数
     */
    @Select("select count(*) from liveness where volunteer_id=#{volunteerId} and date>#{date}")
    Integer getVolunteerLiveNessDay(Integer volunteerId, Timestamp date);

    /**
     * 查询当日的活跃志愿者
     */
    List<Volunteer> getLiveNessVolunteer(Timestamp today);

    /**
     * 根据地区查询当日活跃人数
     */
    Integer getLiveNessNumByPlace(Admin admin, Timestamp today);
}
